<template>
  <ConfigProvider :locale="refLocale">
    <router-view></router-view>
  </ConfigProvider>
</template>

<script lang="ts">
import { defineComponent, ref, Ref } from "vue";
import moment from "moment";
import "moment/dist/locale/zh-cn";
import { ConfigProvider } from "ant-design-vue";
import zhCN from "ant-design-vue/es/locale/zh_CN";
import enUS from "ant-design-vue/es/locale/en_US";
import { Locale } from "ant-design-vue/lib/locale-provider";
import { getLocale } from "/@/kit/i18n-kit";
import { i18nCNKey, i18nUSKey } from "./framework/profile";

/**
 *得到antdvue的语言
 */
const getAntdvLocale = (i18nLocale: string): Locale => {
  let antdvLocale: Locale = null;
  switch (i18nLocale) {
    case i18nUSKey:
      antdvLocale = enUS;
      break;
    case i18nCNKey:
      antdvLocale = zhCN;
      break;
  }
  return antdvLocale;
};

export default defineComponent({
  name: "App",
  components: {
    ConfigProvider,
  },
  setup() {
    const i18nLocale = getLocale();
    const refLocale: Ref<Locale> = ref(getAntdvLocale(i18nLocale));
    moment.locale(i18nLocale);
    return {
      refLocale,
    };
  },
});
</script>
